package com.web;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;


public class BaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得方法名称
        String m = req.getParameter("m");
        //获得对象的类型
        Class<? extends BaseServlet> aClass = this.getClass();

        try {
            //获得方法
            Method method = aClass.getDeclaredMethod(m, HttpServletRequest.class, HttpServletResponse.class);
             //调用方法
            method.invoke(this,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
